<?php

namespace Action\User;

class CheckOpenID extends \Library\Action {

	public function execute() {
		parent::execute();
		
		$openid = trim($this->getParam( 'openid' ));
		
		$check = \Library\Checker\OpenIDChecker::check( $openid );
		if( $check !== true ) {
			return array(
				'valid' => false,
				'message' => $check
			);
		}
		
		if( _q()->getC( 'auth_openids', array( 'openid' => $openid ) ) ) {
			return array(
				'valid' => false,
				'message' => 'OpenID already used'
			);
		}
		
		return array( 
			'valid' => true
		);
	}
}
